<template>
	<view>
		<Header title="申请退款" :showBack="true"></Header>
		<view class="container">
			<!-- 头像，名称，班级，学校 -->
			<view class="user-avatar-school">
				<view class="avatar-box">
					<image src="../../static/userCode.png" class="avatar"></image>
				</view>
				<view class="school-name">
					<view class="name">{{info.ownerName || '---'}} <text style="color: #fa4472">{{info.isSign?'已签约代扣':(info.isGather?'已采集未签约':'未采集')}}</text></view>
					<view class="school">{{info.organizationName}}</view>
					<view class="school">{{info.gradeName}}</view>
					<view style="display: flex;align-items: center;font-size: 24upx;	">
						<view :class="info.cardNo?'':'trans'">卡号：{{info.cardNo}}</view>
					</view>
				</view>
			</view>
			<view class="amount-box">
				<view class="title left-line">余额说明</view>
				<view class="amount-count">您当前余额：{{info.amount}} (元)</view>
			</view>
			<view class="refund-box" v-if="list.isAllowRefund">
				<view class="title left-line">充值记录（最近一次）</view>
				<view class="list">
					<view class="items">充值单号：{{list.rechargeNo || '---'}}</view>
					<view class="items">充值金额：{{list.rechargeAmount || '0'}} (元)</view>
					<view class="items">充值时间：{{list.rechargeTime || '---'}}</view>
				</view>
				<view class="refund-btn" @click="refundAmount">申请退款</view>
			</view>
			<view class="refund-box" v-else>
				<view class="error-text">抱歉，您暂无可退款金额</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { WEXIN_APPID, HUASHOU_SUPPORT, SHOW_MAKECARD, IS_NORMAL } from '@/config.js';
	export default {
		data() {
			return {
				info:uni.getStorageSync('info'),
				baseUrl: getApp().globalData.baseUrl,
				modalInfo: {
					showModal: false,
					title: '绑定家长手机',
					placeholder: '请输入手机号',
					content: ''
				},
				list: {}
			}
		},
		onShow(e) {
			this.getRefundAmountInfo()
		},
		methods: {
			getRefundAmountInfo(){
				this.$http(`/service/api/student/getRefundAmountInfo?memberCardId=${this.info.id}`,{},res=>{
					if(res.data.statusCode == 200){
						this.list = res.data.data
					}
				},"POST",err=>{
					uni.showToast({
						title: JSON.stringify(err.data.errors)
					})
				})
			},
			refundAmount(){
				uni.showModal({
					content: `您确定申请退款 ${this.list.rechargeAmount} (元)?`,
					success: (res) => {
						if(res.confirm){
							this.$http(`/service/api/student/refundAmount?memberCardId=${this.info.id}`,{},res=>{
								console.log(res)
								if(res.data.statusCode == 200){
									uni.showToast({
										title: '提交成功!',
									})
									setTimeout(()=>{
										uni.navigateBack()
									},1500)
								}else{
									uni.showToast({
										title: res.data.errors,
										icon: 'none'
									})
								}
							},"POST",err=>{
								uni.showToast({
									title: JSON.stringify(err.data.errors),
									icon: 'none'
								})
							})
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.commons{
		background: #fff;
		border-radius: 16upx;
		box-shadow: 0 3upx 20upx 1upx rgba(247, 200, 122, .2);
		margin-top: 30upx;
		padding: 20upx;
		.title{
			font-size: 30upx;
			font-weight: bold;
			color: #333;
		}
	}
	.user-avatar-school{
		padding: 30upx 20upx 60upx;
		display: flex;
		.avatar-box{
			width: 120upx;
			height: 120upx;
			border-radius: 50%;
			padding: 10upx;
			background: #fff;
			margin-right: 36upx;
			.avatar{
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}
		.school-name{
			>view{margin-top: 16upx;}
			.name{ font-size: 32upx; text{ font-size: 24upx;margin-left: 6upx; }}
			.school{ font-size: 26upx; width: 456upx; }
			.trans{ color: transparent; }
		}
	}
	.box{
		border-radius: 16upx;
		background: #fff;
		box-shadow: 0 3upx 20upx 1upx rgba(247, 200, 122, .2);
		padding: 44upx 20upx 0;
		display: flex;
		flex-wrap: wrap;
		.item{
			width: 25%;
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-bottom: 58upx;
			image{
				width: 46upx;
				height: 46upx;
				margin-bottom: 16upx;
			}
			view{
				font-size: 26upx;
			}
		}
	}
	.amount-box{
		.commons();
		.amount-count{
			width: 100%;
			text-align: center;
			font-size: 32rpx;
			margin: 20rpx;
		}
	}
	.refund-box{
		.commons();
		.list{
			padding: 30rpx 0 20rpx 40rpx;
			font-size: 28rpx;
			.items{
				height: 62rpx;
				display: flex;
				align-items: center;
			}
		}
		.refund-btn{
			width: 320rpx;
			height: 68rpx;
			background: #ff9200;
			color: #fff;
			border-radius: 12rpx;
			text-align: center;
			line-height: 68rpx;
			margin: 60rpx auto 0;
		}
		.error-text{
			text-align: center;
			margin: 60rpx auto;
		}
	}
</style>
